<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<base href="<%=basePath%>">
<script type="text/javascript" charset="gbk">
window.UEDITOR_HOME_URL = "/mcstu/ueditor/";//编辑器项目路径
	</script>

<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>ueditor/editor_all.js"></script> 
<div class=" row-fluid">
<div  class="" style='background-color: #eee;height:100px;'>
		<h3><c:choose>
		<c:when test="${news.bn=='news' }"><h1 align="center">修改新闻</h1></c:when>
		<c:when test="${news.bn=='bulletin' }">修改公告</c:when>
		</c:choose>
</h3>
	</div>
	<div class="span12 borderColor"  >
		<form action="<%=basePath %>backend/updatenew/${news.id}" method="post" id='newsForm'>

			<div class="row">
              <div class="col-sm-6 input-group">
                 <span class="input-group-addon">类型</span>
                  <select class="form-control" id='bnkind' name='bn'>
                  <option value='news'>新闻</option>
                  <option value="bulletin">公告</option>
                  </select>
                  <span></span>
               </div>
               <br/>
               <br/>
               <div class="col-md-6 input-group" >
                 <span class="input-group-addon">归属</span>
                 <div id='newskind' style='margin-left:6px;' >
                   <input id='n1' class='checkbox1 news1' type="checkbox"  value="0001" name='putong'>普通新闻
                   <input id='n2' class='checkbox1 news1'  type="checkbox" value="0010" name='dangjian'>党建新闻
                   <input id='n3' class='checkbox1 news1'  type="checkbox" value="0100" name='student'>学生新闻
                   <input id='n4' class='checkbox1 news1'  type="checkbox" value="1000" name='zhaoshengjiuye'>招生就业新闻
                 </div>
                 <div id='bulletinkind'  style='margin-left:6px;'>
                   <input id='b1' class='checkbox1 bullet1' type="checkbox" value="001" name='putong'>普通公告
                   <input id='b2' class='checkbox1 bullet1' type="checkbox" value="010" name='dangjian'>党建公告
                   <input id='b3' class='checkbox1 bullet1' type="checkbox" value="100" name='student'>学生公告
                   <input id='b4' class='checkbox1 bullet1' type="checkbox" value="1000" name='student'>招生就业公告
                 </div>
               </div>
               <!-- Optional: clear the XS cols if their content doesn't match in height -->
               <div class="clearfix visible-xs"></div>
              
           </div>
           <div class="row">
          <div class="col-sm-9 input-group" style='margin-top:10px;'>
                 <span class="input-group-addon">标题</span>
                 <input class="form-control " value="${news.title }" style='height:30px;' type="text" name="title" >
              <span></span>
              </div>
              </div>
			  <div style='margin-top: 10px;'>
			  
		       <script  id="editor" ></script>
		       </div>
	
		<input  type="submit" value="完成" style="margin-left: 700px;margin-top: 10px;" class="btn btn-info" onclick="return getContent();"/></div>
		<input id="content1" type="hidden" name="content" value='${news.content }'>
		<input id='belong' name='belong' type="hidden" value="${news.belong }">
	    <input id='nb1' value="${news.bn }"  type="hidden"/>
	   </form>
	
	<script type="text/javascript">
	var editor = new UE.ui.Editor();
    editor.render("editor");
	$(function(){
		var nb = $("#nb1").val();
		var content = $("#content1").val();
         editor.ready(function(){
           editor.setContent(content);
          });
		var belong = $("#belong").val();
		$("#bnkind").val(nb);
		if($("#bnkind").val()=="news")//选择了新闻
		{
			$(".news1").each(function(){
				
				var value = parseInt($(this).val(),2);
				var b = parseInt(belong,2);
			    if((value & b) != 0)
			    {
			    	$(this).attr("checked",true);
			    }
			});
		}else{  //选择了公告
			$(".bullet1").each(function(){
				$("#newskind").hide();
				$("#bulletinkind").show();
				var value = parseInt($(this).val(),2);
				var b = parseInt(belong,2);
			    if((value & b) != 0)
			    {
			    	$(this).attr("checked",true);
			    };
			});
		};
		
	});
    function getContent() {
    var str= "";
         editor.ready(function(){
        	 str= editor.getContent();
          });
       
        alert(str);
        $("#content1").val(str);
        var str="";
        var result = 0;
        if($("#bnkind").val()=="news")
       	{
       	 $(".news1").each(function(){
          	  if($(this).attr("checked") == true || $(this).attr("checked") == "checked")
    			  {
          		  str=$(this).val();
          		  result = parseInt(result,10) + parseInt(str,10);
    			  }
       	 });
       	}else{
       		 $(".bullet1").each(function(){
                 	
                 	  if($(this).attr("checked") == true || $(this).attr("checked") == "checked")
         			  {
                 		  str=$(this).val();
                 		  result = parseInt(result,10) + parseInt(str,10);
         			  }
              	 });
       	}
       switch(result)
       {
       case 1:
    	   result = "0001";
    	   break;
       case 10:
    	   result = "0010";
    	   break;
       case 100:
    	   result="0100";
    	   break;
       case 11:
    	   result = "0011";
    	   break;
       case 101:
    	   result = "0101";
    	   break;
       case 110:
    	   result = "0110";
    	   break;
       case 111:
    	   result = "0111";
    	   break;
       }
   
       alert(result + "--" );
       $("#belong").val(result);
       result=0;
        if(document.getElementById('title').value.length==0||str.length==0)
        	{
        	  alert('还有尚未填写的内容！');
        	  document.getElementById('title').focus();
        	  return false;
        	}
        return true;
    }
</script>
	</div>
